/*
 * @Description: 会场热力图
 * @Author: zy
 * @Date: 2021-04-12 09:46:12
 * @LastEditors: zy
 * @LastEditTime: 2021-04-12 16:58:59
 */
import * as d3 from 'd3'

export function renderHotMap (sendors) {
  let range = d3.extent(sendors, function (d) {
    return d[1]
  })
  let useColor = ['#1f77b4', '#cf5b5b',
    '#3a9699',
    '#829899', '#80a894',
    '#093844',
    '#35804d', '#ffe654']
  let color = d3.scaleLinear().domain(range).range(useColor)
  let gsensors = d3.select('.sensors').selectAll('g')
  gsensors.select('rect')
    .style('fill', function (d) {
      let thisColor = ''
      d.peopleNum = 0
      for (let i = 0; i < sendors.length; ++i) {
        if (d.sid === parseInt(sendors[i][0])) {
          thisColor = color(sendors[i][1])
          d.peopleNum = sendors[i][1]
          break
        } else {
          thisColor = d3.select(this).style('fill')
        }
      }
      return thisColor
    })
  gsensors.select('text')
    .filter(d => d.peopleNum !== 0)
    .text(d => d.peopleNum)
}
